var express = require('express');
var router = express.Router();

var api = require('../server/api');

var sessionLog = require('./sessionLog');   //验证session.token

/* 登录 */
router.get('/login', function(req, res, next) {
    api.login(req, res, next);
});

/* 排名 */
router.get('/ranking/list', sessionLog, function(req, res, next) {
    api.ranking(req, res, next);
});
/* 查询最近解决方案发布 */
router.get('/solve/recent', sessionLog, function(req, res, next) {
    api.solve(req, res, next);
});

/* 查询最近解决方案发布
* userId  用户ID Int
* */
router.get('/ranking/findById', sessionLog, function(req, res, next) {
    api.rankingId(req, res, next);
});

/* 根据解决方案ID查询解决方案详情
 * id  解决方案ID Int
 * */
router.get('/solve/select', sessionLog, function(req, res, next) {
    api.solveSelect(req, res, next);
});

/* 点赞
* solveId  解决方案ID Int
* */
router.post('/solve/likes', sessionLog, function(req, res, next) {
    api.likes(req, res, next);
});

/* 添加收藏
 * type  类型(1.错误码 2.解决方案) Int
 * id   相关ID   Int
 * */
router.post('/user/collection', sessionLog, function(req, res, next) {
    api.collectionAdd(req, res, next);
});

/* 取消收藏
 * type  类型(1.错误码 2.解决方案) Int
 * id   相关ID   Int
 * */
router.post('/user/collection/delete', sessionLog, function(req, res, next) {
    api.collectionDel(req, res, next);
});

/* 请求接口错误处理 */
router.get('/reqError', function(req, res, next) {
    res.render('reqError', { message: '请求接口错误处理' });
});

module.exports = router;
